package com.example.demo.dao;

import com.example.demo.model.LaterView;
import org.apache.ibatis.jdbc.SQL;

public class LaterViewSqlProvider {

    /**
     * 根据字段是否为空保存 
     * @param record LaterView
     * @return String
     */
    public String insertSelective(LaterView record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("later_view");
        
        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=INTEGER}");
        }
        
        if (record.getUserId() != null) {
            sql.VALUES("user_id", "#{userId,jdbcType=INTEGER}");
        }
        
        if (record.getNewsId() != null) {
            sql.VALUES("news_id", "#{newsId,jdbcType=INTEGER}");
        }
        
        if (record.getCreateTime() != null) {
            sql.VALUES("create_time", "#{createTime,jdbcType=datetime}");
        }
        
        return sql.toString();
    }

    /**
     * 根据字段是否为空更新 
     * @param record LaterView
     * @return String
     */
    public String updateByPrimaryKeySelective(LaterView record) {
        SQL sql = new SQL();
        sql.UPDATE("later_view");
        
        if (record.getUserId() != null) {
            sql.SET("user_id = #{userId,jdbcType=INTEGER}");
        }
        
        if (record.getNewsId() != null) {
            sql.SET("news_id = #{newsId,jdbcType=INTEGER}");
        }
        
        if (record.getCreateTime() != null) {
            sql.SET("create_time = #{createTime,jdbcType=datetime}");
        }
        
        sql.WHERE("id = #{id,jdbcType=INTEGER}");
        
        return sql.toString();
    }
}